jQuery(document).ready(function()
{
	jQuery("#checkall").click(function()
 	{
		var checked_status = this.checked;
		jQuery("input[type=checkbox]").each(function()
		{
			this.checked = checked_status;
			change(this);	
		});
 	});
	jQuery("input[type=checkbox]").click(function()
 	{
		var i=0;
		var flag=0;
 	        var checked_status = this.checked;
 	        jQuery("input[type=checkbox]").each(function()
		{
		  i++;
		  if(this.checked && i!=1)
		  {
			flag++;
		  }
		  else if(i!=1)
		  {
			flag--;
		  }
		});
		if(flag==(i-1))
		{
		  	jQuery("#checkall").attr('checked',true);
		}else{
  			jQuery("#checkall").attr('checked',false);
		}
		
		change(this);
 	});
	function change(chk)
	{
		var jQuerytr = jQuery(chk).parent().parent();
		if(jQuerytr.attr('id'))
		{
			if(jQuerytr.attr('class')=='selectedrow' && !chk.checked)
				jQuerytr.removeClass('selectedrow').addClass('grayback');
			else
				jQuerytr.removeClass('grayback').addClass('selectedrow');
		}
	}
	jQuery("#frmAction").submit(function(){
		var flag = false;
		if(jQuery("#action").attr('value')=='')
		{
			jQuery("#acterr").text("Please select an action.").show().fadeOut(3000);
			return false;
		}
		jQuery("input[type=checkbox]").each(function()
		{
			var $tr = jQuery(this).parent().parent();
			
			if($tr.attr('id'))
				if(this.checked == true)
				{
					
					flag = true;
				}
		});
		
		if (flag == false) {
			jQuery("#acterr").text("Please select a record.").show().fadeOut(3000);
			return false;
		}
		if(confirm('Are you sure you want to "'+jQuery("#action").attr('value')+'" the selected record(s)?'))
			return true;
		else
			return false;
    });
	jQuery("#msg").fadeOut(5000);
});

jQuery(document).ready(function()
{
	
var dates = jQuery( "#fromDate, #toDate" ).datepicker({
                       changeMonth: true,
			changeYear: true,
                        dateFormat:"mm/dd/yy",                        
                        defaultDate: "+1w",
			maxDate:"D",
                        numberOfMonths: 1,
                        onSelect: function( selectedDate ) {
                                var option = this.id == "fromDate" ? "minDate" : "maxDate",
                                        instance = $( this ).data( "datepicker" );
                                        date = $.datepicker.parseDate(
                                                instance.settings.dateFormat ||
                                                $.datepicker._defaults.dateFormat,
                                                selectedDate, instance.settings );
                                dates.not( this ).datepicker( "option", option, date );
                        }
                });

	jQuery("#msg").fadeOut(5000);
});